package cn.iocoder.yudao.module.dbit.controller.admin.onlineresumesinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dbit.controller.admin.onlineresumesinfo.vo.*;
import cn.iocoder.yudao.module.dbit.dal.dataobject.onlineresumesinfo.OnlineResumesInfoDO;
import cn.iocoder.yudao.module.dbit.service.onlineresumesinfo.OnlineResumesInfoService;

@Tag(name = "管理后台 - 在线简历信息")
@RestController
@RequestMapping("/dbit/online-resumes-info")
@Validated
public class OnlineResumesInfoController {

    @Resource
    private OnlineResumesInfoService onlineResumesInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建在线简历信息")
    @PreAuthorize("@ss.hasPermission('dbit:online-resumes-info:create')")
    public CommonResult<Integer> createOnlineResumesInfo(@Valid @RequestBody OnlineResumesInfoSaveReqVO createReqVO) {
        return success(onlineResumesInfoService.createOnlineResumesInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新在线简历信息")
//    @PreAuthorize("@ss.hasPermission('dbit:online-resumes-info:update')")
    public CommonResult<Boolean> updateOnlineResumesInfo(@Valid @RequestBody OnlineResumesInfoSaveReqVO updateReqVO) {
        onlineResumesInfoService.updateOnlineResumesInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除在线简历信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('dbit:online-resumes-info:delete')")
    public CommonResult<Boolean> deleteOnlineResumesInfo(@RequestParam("id") Integer id) {
        onlineResumesInfoService.deleteOnlineResumesInfo(id);
        return success(true);
    }

    @GetMapping("/defaulted")
    @Operation(summary = "设置默认简历简历")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> defaultedOnlineResumesInfo(@RequestParam("id") Integer id) {
        onlineResumesInfoService.defaultedOnlineResumesInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得在线简历信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('dbit:online-resumes-info:query')")
    public CommonResult<OnlineResumesInfoRespVO> getOnlineResumesInfo(@RequestParam("id") Integer id) {
        OnlineResumesInfoDO onlineResumesInfo = onlineResumesInfoService.getOnlineResumesInfo(id);
        return success(BeanUtils.toBean(onlineResumesInfo, OnlineResumesInfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得在线简历信息分页")
    @PreAuthorize("@ss.hasPermission('dbit:online-resumes-info:query')")
    public CommonResult<PageResult<OnlineResumesInfoRespVO>> getOnlineResumesInfoPage(@Valid OnlineResumesInfoPageReqVO pageReqVO) {
        PageResult<OnlineResumesInfoDO> pageResult = onlineResumesInfoService.getOnlineResumesInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, OnlineResumesInfoRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出在线简历信息 Excel")
    @PreAuthorize("@ss.hasPermission('dbit:online-resumes-info:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportOnlineResumesInfoExcel(@Valid OnlineResumesInfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<OnlineResumesInfoDO> list = onlineResumesInfoService.getOnlineResumesInfoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "在线简历信息.xls", "数据", OnlineResumesInfoRespVO.class,
                        BeanUtils.toBean(list, OnlineResumesInfoRespVO.class));
    }

}